package at.technikum.fotoalbum.database;

import java.util.ArrayList;
import java.util.Iterator;

import at.technikum.fotoalbum.beans.*;

public class DatabaseTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Person testuser = new Person();
		Person newuser = new Person();
		Image testimage = new Image();
		boolean success;
		
		String username = "Testuser4711";
		ArrayList<Person> userarray = new ArrayList();
		ArrayList<Image> imagearray = new ArrayList();
		Iterator i;
		
		// Establish DB Connection
		DatabaseConnector dbConnector = new DatabaseConnector();
		
/*
		newuser.setNick("");
		newuser.setVorname("");
		newuser.setNachname("");
		newuser.setPassword("");
		newuser.setEmail("");
*/
		
		/*
		newuser.setNick("testuser8");
		newuser.setPassword("testpassword8neu");
		newuser.setVorname("testfirstname8neu");
		newuser.setNachname("testlastname8neu");
		newuser.setEmail("testemail8neu@123.at");
		*/
		
		newuser.setNick("testuser8");
		newuser.setPassword("testpassword8");
		newuser.setVorname("testfirstname8");
		newuser.setNachname("testlastname8");
		newuser.setEmail("testemail8@123.at");
		
		
		
/*
		boolean success = dbConnector.editUser(newuser);
		System.out.println("boolean editUser(User) liefert: " + success);
		System.out.println();
*/		
		
		success = dbConnector.existsUser("testuser8");
		System.out.println("boolean existsUser() liefert: " + success);
		System.out.println();
		
		success = dbConnector.checkLoginUser ("testuser8", "testpassword8");
		System.out.println("boolean CheckLoginUser() liefert: " + success);
		System.out.println();
		
		success =  dbConnector.confirmUser(null);
		System.out.println("boolean confirmUser() liefert: " + success);
		System.out.println();
		
		
		success =  dbConnector.changePassword("Testuser2", "password222");
		System.out.println("boolean changePassword() liefert: " + success);
		System.out.println();
		
		
		
		/*
		success = dbConnector.deleteAllImagesFromUser ("testuser4711");
		System.out.println("boolean deleteAllImagesFromUser() liefert: " + success);
		System.out.println();
		*/
		
		
		/*
		long id = dbConnector.createNewUser(newuser);
		System.out.println("long createNewUser(newuser) liefert: " + id);
		*/
		
		/*
		success = dbConnector.deleteUser("testuser8");
		System.out.println("boolean deleteUser() liefert: " + success);
		System.out.println();
		*/
		
		/*
		boolean success = dbConnector.setAdmin("testuser9");
		System.out.println("boolean setAdmin() liefert: " + success);
		System.out.println();
		*/
		
		/*
		testuser = dbConnector.getUserFromUsername(username);
		System.out.println("Userdaten:");
		System.out.println("Username: " + testuser.getNick());
		System.out.println("Password: " + testuser.getPassword());
		System.out.println("First name: " + testuser.getVorname());
		System.out.println("Last name: " + testuser.getNachname());
		System.out.println("Email: " + testuser.getEmail());
		System.out.println("isAdmin?: " + testuser.isAdmin());
		System.out.println("isConfirmed?: " + testuser.isConfirmed());
		System.out.println();
		*/
		
		System.out.println("*** Ausgabe aller User in der DB ***");
		userarray = dbConnector.getAllUsers();
		i = userarray.iterator();
		while (i.hasNext()) {
			testuser = (Person) i.next();
			System.out.println();
			System.out.println("Userdaten:");
			System.out.println("ID: " + testuser.getId());
			System.out.println("Username: " + testuser.getNick());
			System.out.println("Password: " + testuser.getPassword());
			System.out.println("First name: " + testuser.getVorname());
			System.out.println("Last name: " + testuser.getNachname());
			System.out.println("Email: " + testuser.getEmail());
			System.out.println("isAdmin?: " + testuser.isAdmin());
			System.out.println("isConfirmed?: " + testuser.isConfirmed());
			System.out.println();			
		}
		
		System.out.println("*** Ausgabe aller Images in der DB ***");
		imagearray = dbConnector.getAllImages();
		i = imagearray.iterator();
		while (i.hasNext()) {
			testimage = (Image) i.next();
			System.out.println();
			System.out.println("Imagedaten:");
			System.out.println("ID: " + testimage.getID());
			System.out.println("Name: " + testimage.getName());
			System.out.println("Path: " + testimage.getPath());
			System.out.println("Filename: " + testimage.getFilename());
			System.out.println("Date: " + testimage.getDate());
			System.out.println("Username: " + testimage.getNick());
			System.out.println();			
		}
		
		System.out.println("*** Ausgabe aller Images eines Users ***");
		imagearray = dbConnector.getImagesFromUser("ande");
		i = imagearray.iterator();
		while (i.hasNext()) {
			testimage = (Image) i.next();
			System.out.println();
			System.out.println("Imagedaten:");
			System.out.println("ID: " + testimage.getID());
			System.out.println("Name: " + testimage.getName());
			System.out.println("Path: " + testimage.getPath());
			System.out.println("Filename: " + testimage.getFilename());
			System.out.println("Date: " + testimage.getDate());
			System.out.println("Username: " + testimage.getNick());
			System.out.println();			
		}
		
		/*
		testimage = dbConnector.getImageFromImagename("ande2");
		System.out.println("Imagedaten:");
		System.out.println("ID: " + testimage.getID());
		System.out.println("Name: " + testimage.getName());
		System.out.println("Path: " + testimage.getPath());
		System.out.println("Filename: " + testimage.getFilename());
		System.out.println("Date: " + testimage.getDate());
		System.out.println("Username: " + testimage.getNick());
		*/
		/*
		int j = (int) (Math.random());
		System.out.println("Zufallszahl: " + j);
		*/
		
		//Image testimage = new Image("imagename44", "D:images", "testimage44567.jpg");
		//dbConnector.createImage(testimage, username);
		
		
		
		// Test ob Image existiert
		/*
		boolean a = dbConnector.existsImage("imagename123");
		if (a) System.out.println("Bildname bereits vorhenden");
		else System.out.println("Bildname noch frei");
		*/
		
		
		
		
		
		// Close DB Connection
		dbConnector.closeDBConnection();
		
	}

}
